package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.Result;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/eduservice/bannerfront")
@Slf4j
public class IndexFrontController {

    @Autowired
    private EduCourseService courseService;
    @Resource
    private EduTeacherService teacherService;

    @GetMapping("/index")
    public Result index() {
        //查询所有的课程，根据id进行匹配，并显示8条
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 8");
        List<EduCourse> courseList = courseService.list(wrapper);

        //查询所有的讲师，根据id进行匹配，并限制4条
        QueryWrapper<EduTeacher> wra = new QueryWrapper<>();
        wra.orderByDesc("id");
        wra.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(wra);
        log.info("课程数据: => {}, 讲师数据: => {}",courseList,teacherList);

        return Result.ok().data("courseList",courseList).data("teacherList",teacherList);
    }
}
